package com.tekj.cxqcb.view.Module.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tekj.cxqcb.MainBActivity;
import com.tekj.cxqcb.R;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.QueryCarDealerDetailsPrivateBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import common.base.activity.BaseActivity;
import common.base.operationHelper.Bean.BindingViewBean;
import common.tool.Tools;
import es.dmoral.toasty.Toasty;

/**
 * 私有车行
 */
public class TrafficManagementDetailsActivity extends BaseActivity {
    @BindView(R.id.img_back)
    ImageView imgBack;
    @BindView(R.id.tv_l)
    TextView tvL;
    @BindView(R.id.ll_back)
    LinearLayout llBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_r)
    ImageView ivR;
    @BindView(R.id.tv_r)
    TextView tvR;
    @BindView(R.id.ll_right)
    LinearLayout llRight;
    @BindView(R.id.rl_title_bg)
    RelativeLayout rlTitleBg;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_szdq)
    TextView tvSzdq;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.tv_frname)
    TextView tvFrname;
    @BindView(R.id.tv_frphone)
    TextView tvFrphone;
    @BindView(R.id.img_photo)
    ImageView imgPhoto;
    @BindView(R.id.img_photo2)
    ImageView imgPhoto2;
    @BindView(R.id.img_photo3)
    ImageView imgPhoto3;
    @BindView(R.id.img_photo4)
    ImageView imgPhoto4;
    @BindView(R.id.ll_qtzl)
    LinearLayout llQtzl;

    BusinessDao businessDao;


    @Override
    public void init() {
        tvTitle.setText("车行管理");
        businessDao = new BusinessDao(activity, activity);
        businessDao.QueryCarDealerDetailsPrivate(MainBActivity.User.getUserId());
    }

    @Override
    public int setLayout() {
        return R.layout.activity_traffic_management_details;
    }

    @Override
    public void initLoadStart() {
        loading.show();
    }

    @Override
    public void initLoadEnd() {
        loading.dismiss();
    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 私有车行:
                QueryCarDealerDetailsPrivateBean typeBean = (QueryCarDealerDetailsPrivateBean) bindingViewBean.getBean();
                if (typeBean.getCode().equals("0000000")) {
                    try {
                        setData(typeBean.getData());
                    }catch (NullPointerException e){
                        Toasty.normal(activity,"门店信息获取失败").show();
                        finish();
                    }
                }
                break;
        }
    }


    @OnClick(R.id.ll_back)
    public void onViewClicked() {
        finish();
    }

    void setData(QueryCarDealerDetailsPrivateBean.DataBean bean) {

        tvName.setText(bean.getCarDealerName());
        tvSzdq.setText(bean.getRegion());
        tvAddress.setText(bean.getDetailedAddress());
        tvFrname.setText(bean.getLegalName());
        tvFrphone.setText(bean.getPhone());
        Tools.picassoNetwork(bean.getStorefrontPicture(), imgPhoto);
        Tools.picassoNetwork(bean.getBusiness(), imgPhoto2);
        Tools.picassoNetwork(bean.getCooperationAgreement(), imgPhoto3);
        if (bean.getAdj() == null || bean.getAdj().equals("")) {
            imgPhoto4.setVisibility(View.GONE);
            llQtzl.setVisibility(View.GONE);
        } else
            Tools.picassoNetwork(bean.getAdj(), imgPhoto4);

    }

}
